package com.homework.hw1028;

import java.util.Scanner;

public class Test {
    public static void welcome() {
        System.out.println("----------欢迎进入游戏世界----------\n");
        System.out.println("******************");
        System.out.println("***  猜拳,开始  ***");
        System.out.println("******************\n");
        System.out.println("出拳规则:1.剪刀 2.石头 3.布");
    }

    public static boolean ifNext() {
        Scanner input = new Scanner(System.in);
        while (true) {
            System.out.println("是否开启下一局?(y/n)");
            String ifContinue = input.next();
            if (ifContinue.equals("y")) {
                return true;
            } else if (ifContinue.equals("n")) {
                return false;
            } else {
                System.out.println("输入非法字符,请重新输入");
            }
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        welcome();
        do {
            Person person = new Person();
            Computer computer = new Computer();
            Rule rule = new Rule();

            int pchoice = 0;
            while (true) {
                System.out.println("请选择对方角色(1.刘备 2.孙权 3.曹操):");
                pchoice = input.nextInt();
                if (pchoice == 1 || pchoice == 2 || pchoice == 3) {
                    break;
                } else {
                    System.out.println("输入非法字符,请重新选择");
                }
            }

            System.out.println("请输入你的姓名:");
            String pname = input.next();

            rule.ready(pname, pchoice, person, computer);
            rule.ifStart();
            int time = 0;
            do {
                System.out.println("请出拳:1.剪刀 2.石头 3.布(输入相应数字):");
                int perchoice = input.nextInt();
                int comchoice = computer.getNum();
                String perresult = person.ppunch(perchoice);
                String comresult = computer.cpunch(comchoice);

                System.out.println("你出拳:" + perresult);
                System.out.println(computer.getName() + "出拳:" + comresult);

                rule.gameResult(perresult, comresult, rule, person, computer);
                time++;
            } while (rule.ifContinue());
            System.out.println(computer.getName() + "  VS  " + person.getName());
            System.out.println("对战次数:" + time);
            int a = rule.gameScore(person, computer);
            String end = rule.gameend(a);
            System.out.println(end);
        } while (ifNext());
        System.out.println("游戏结束!");
    }
}
